package taller2.view.windows.MainWindows;

import java.awt.GridBagLayout;

import javax.swing.JPanel;

import taller2.controller.listeners.evaluateMeButtons.EvaluateMeButtonListener;
import taller2.controller.listeners.evaluateMeButtons.StronglyConnectedComponentsEvaluateMeButtonListener;
import taller2.interfaces.AlgorithmApplicator;
import taller2.interfaces.Graph;
import taller2.model.factorys.GraphFactory;
import taller2.utils.Constants;
import taller2.utils.Constants.Colores;
import taller2.utils.Point;
import taller2.utils.Utils;
import taller2.view.draws.GraphDrawer;
import taller2.view.menus.CodeBrowser;
import taller2.view.menus.CodeMenu;
import taller2.view.menus.MainEdittingMenus.MainEdittingMenu;
import taller2.view.menus.MainEdittingMenus.StronglyConnectedMainEdittingMenu;
import taller2.view.windows.MyWindow;

public class StronglyConnectedComponentsMainWindow extends MainWindow{
	Graph reference;
	GraphDrawer referenceDrawer;
	AlgorithmApplicator appl;

	public StronglyConnectedComponentsMainWindow(MyWindow parent, String path, boolean directed,
			AlgorithmApplicator algorithmApplicator) {
		super(parent, path, directed, algorithmApplicator, new StronglyConnectedComponentsEvaluateMeButtonListener(algorithmApplicator));
		appl = algorithmApplicator;
		
		reference = GraphFactory.directedGgraphInstance();
		
		reference.add(new Point(30, 50), "Visited");
		reference.add(new Point(110, 50), "");
		reference.getNodes().get(0).changeColor(Colores.red);
		reference.getNodes().get(1).setMarker("NUM/COMP");

		referenceDrawer = new GraphDrawer(reference, Constants.selectedColor, Constants.unSelectedColor);
		referenceDrawer.resize(50, 4, Constants.SampleTextSize);

		area.addDrawable(referenceDrawer);
	}

	//existe para redefinir cosas:
	@Override
	protected MainEdittingMenu createMainEdittingMenu(EvaluateMeButtonListener evaluateMe){
		return (new StronglyConnectedMainEdittingMenu(this, area,graph,this.algorithmApplicator,evaluateMe));
	}

	@Override
	protected JPanel crearBrowsers (String path){
		
		JPanel panelBrowsers = new JPanel(new GridBagLayout());
		
		this.browser = new CodeBrowser(path,Constants.fontSize,this.algorithmApplicator,window, graph, true);
		
		Utils.addComponent(panelBrowsers,browser,1,0.7,new Point(0,0));
		
		this.menu = new CodeMenu(browser, panelTexto,Constants.fontSize,Constants.codePath);
		
		return panelBrowsers;
	}
	
	public void aplicarCambios(Graph graph){
		this.graph = graph; 
		this.drawer.setGraph(graph);
		this.browser.setGraph(graph);
		
		this.window.removeComponent(selector);
		
		selector = createMainEdittingMenu(new StronglyConnectedComponentsEvaluateMeButtonListener(appl));
		this.window.addComponent(selector,1,0,new Point(0,1));
		
		redraw();
	}

}
